import request from '@/utils/request'
import { getMpAppid } from '@/utils/future/toolkit'


// 微信配置相关

// 获取微信配置
export function wxConfigGet() {
  return request({
    url: '/wx/config/info',
    method: 'get'
  })
}

// 更新微信配置
export function wxConfigPut(data) {
  return request({
    url: '/wx/config/info',
    method: 'put',
    data
  })
}


// 当前公众号列表
export function accountList() {
  return request({
    url: '/manage/wxAccount/list',
    method: 'get'
  })
}



// 获取公众号列表
export function fetchWxAccountList() {
  return request({
    url: '/manage/wxAccount/page?appid='+getMpAppid(),
    method: 'get'
  })
}

export function addWxAccount(data) {
  return request({
    url: '/manage/wxAccount/save?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}

export function delWxAccount(data) {
  return request({
    url: '/manage/wxAccount/delete?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}


// 回复规则
export function fetchWxMsgReplyRuleList() {
  return request({
    url: '/manage/msgReplyRule/list?appid='+getMpAppid(),
    method: 'get'
  })
}

export function addWxMsgReplyRule(data) {
  return request({
    url: '/manage/msgReplyRule/save?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}

export function getWxMsgReplyRule(ruleId) {
  return request({
    url: `/manage/msgReplyRule/info/${ruleId}?appid=`+getMpAppid(),
    method: 'get'
  })
}

export function updateWxMsgReplyRule(ruleId,data) {
  return request({
    url: `/manage/msgReplyRule/info/${ruleId}?appid=`+getMpAppid(),
    method: 'put',
    data
  })
}
export function delWxMsgReplyRule(data) {
  return request({
    url: '/manage/msgReplyRule/delete?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}


// 菜单
export function getMenu() {
  return request({
    url: '/manage/wxMenu/getMenu?appid='+getMpAppid(),
    method: 'get'
  })
}

export function updateMenu(data) {
  return request({
    url: '/manage/wxMenu/updateMenu?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}

// 消息
export function fetchWxMsgList(query) {
  return request({
    url: '/manage/wxMsg/list?appid='+getMpAppid(),
    method: 'get',
    params: query
  })
}


// 粉丝分页
export function wxUserList(data) {
  return request({
    url: '/manage/wxUser/listByIds?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}

// 粉丝列表
export function fetchWxUserList(query) {
  return request({
    url: '/manage/wxUser/list?appid='+getMpAppid(),
    method: 'get',
    params: query
  })
}
// 同步粉丝
export function syncWxUsers() {
  return request({
    url: '/manage/wxUser/syncWxUsers?appid='+getMpAppid(),
    method: 'get'
  })
}
// 删除粉丝
export function deleteWxUsers(query) {
  return request({
    url: '/manage/wxUser/delete?appid='+getMpAppid(),
    method: 'delete',
    params: query
  })
}


// 素材
export function wxAssetsMaterialCount() {
  return request({
    url: '/manage/wxAssets/materialCount?appid='+getMpAppid(),
    method: 'get'
  })
}

export function wxAssetsMaterialNewsInfo() {
  return request({
    url: '/manage/wxAssets/materialNewsInfo?appid='+getMpAppid(),
    method: 'get'
  })
}


export function materialFileBatchGet(query) {
  query.appid = getMpAppid()
  return request({
    url: '/manage/wxAssets/materialFileBatchGet',
    method: 'get',
    params: query
  })
}

export function materialNewsBatchGet(query) {
  query.appid = getMpAppid()
  return request({
    url: '/manage/wxAssets/materialNewsBatchGet',
    method: 'get',
    params: query
  })
}
export function materialFileUpload(data) {
  return request({
    url: '/manage/wxAssets/materialFileUpload?appid='+getMpAppid(),
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: data
  })
}


// 模板

export function fetchMsgTemplateList(query) {
  return request({
    url: '/manage/msgTemplate/list?appid='+getMpAppid(),
    method: 'get',
    params: query
  })
}

export function syncWxTemplate(query) {
  return request({
    url: '/manage/msgTemplate/syncWxTemplate?appid='+getMpAppid(),
    method: 'post',
    data: {}
  })
}
export function sendMsgBatch(data) {
  return request({
    url: '/manage/msgTemplate/sendMsgBatch?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}

export function getMsgTemplate(id) {
  return request({
    url: `/manage/msgTemplate/info/${id}?appid=`+getMpAppid(),
    method: 'get'
  })
}

export function saveMsgTemplate(id,data) {
  return request({
    url: `/manage/msgTemplate/${!id ? 'save' : 'update'}?appid=`+getMpAppid(),
    method: 'post',
    data: data
  })
}

``


// 文章

export function fetcWxMpArticleList(query) {
  return request({
    url: '/manage/article/list?appid='+getMpAppid(),
    method: 'get',
    params: query
  })
}

// 标签

export function wxUserTagsList() {
  return request({
    url: '/manage/wxUserTags/list?appid='+getMpAppid(),
    method: 'get'
  })
}

export function wxUserTagging(mode,data) {
  return request({
    url: `/manage/wxUserTags/${mode=='tagging'?'batchTagging':'batchUnTagging'}?appid=`+getMpAppid(),
    method: 'post',
    data: data
  })
}

export function wxUserTagDelete(tagid) {
  return request({
    url: `/manage/wxUserTags/delete/${tagid}?appid=`+getMpAppid(),
    method: 'post',
    data: {}
  })
}

export function wxUserTagSave(data) {
  return request({
    url: `/manage/wxUserTags/save?appid=`+getMpAppid(),
    method: 'post',
    data: data
  })
}


// 带参数二维码
export function fetchWxQrCodeList(query) {
  return request({
    url: '/manage/wxQrCode/list?appid='+getMpAppid(),
    method: 'get',
    query
  })
}

export function delWxQrCodeicket(data) {
  return request({
    url: '/manage/wxQrCode/delete?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}


export function createTicket(data) {
  return request({
    url: '/manage/wxQrCode/createTicket?appid='+getMpAppid(),
    method: 'post',
    data: data
  })
}
